#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <string.h>
#include "cJSON.h"
#include <stdlib.h>


int main()
{
    //创建共享内存
    int shmid;
    shmid = shmget (0x007 , 1024 , IPC_CREAT|0666);
    if(shmid < 0)
    {
	perror("shmget");
	return -1;
    }
    printf("共享内存创建成功\n");


    //写数据
    char *p = NULL;
    p = shmat(shmid , NULL , 0);
    if( p==(void*)-1 )
    {
    perror("shmat");
    return -1;
    }


    cJSON* root = cJSON_CreateObject();

    cJSON*  = cJSON_CreateString("xiaoming");
    cJSON_AddItemToObject(root , "name" , name);
    
    cJSON_AddNumberToObject(root , "age",14);
    cJSON_AddBoolToObject(root , "gender", 1);
    cJSON_AddNumberToObject(root , "height", 1.65);
    cJSON_AddNullToObject(root , "grade");

    //输出打印
    char* string = cJSON_Print(root);


    //char gp[] = "我是张三hahaha666";
    
    strncpy( p ,  string , 1024);
    
    free(string);
    cJSON_Print(root);
    shmdt(p);

    return 0;
}
